package com.collection.linkedlist;

import java.util.LinkedList;

public class GetFirstAndLastElementLinkedListExample {
	public static void main(String[] args) {
		 
	    //create LinkedList object
	    LinkedList lList = new LinkedList();
	   
	    //add elements to LinkedList
	    lList.add("1");
	    lList.add("2");
	    lList.add("3");
	    lList.add("4");
	    lList.add("5");
	   
	    /*
	     * To get first element from Java LinkedList, use
	     * Object getFirst() method.
	     *
	     * This method returns first element stored in LinkedList.
	     */
	   
	     System.out.println("First element of LinkedList is : " + lList.getFirst());
	 
	    /*
	     * To get last element from Java LinkedList, use
	     * Object getLast() method.
	     *
	     * This method returns last element stored in LinkedList.
	     */
	   
	     System.out.println("Last element of LinkedList is : " + lList.getLast());
	   
	   
	  }
}
